package com.bioroadlab.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.stereotype.Controller;

import com.bioroadlab.pojo.Disease;
import com.bioroadlab.pojo.DiseaseType;

@Controller
public class DiseaseTypeAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	private Disease disease;
	private DiseaseType diseaseType;
	private String sn;

	@Override
	public String execute() throws Exception {
		return null;
	}

	@Action("disease_type")
	public String findDiseaseTypeByDisease() {
		disease = getDiseaseService().findBySn(Integer.parseInt(sn));
		JSONObject json = getDiseaseTypeService().findDiseaseJsonBy(disease);
		diseaseType = getDiseaseTypeService().findByDisease(disease);

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=UTF-8");
		try {
			PrintWriter out = response.getWriter();
			String jsonString = json.toString();
			out.print(jsonString);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Action("getdisease")
	public String getDiseaseTypeByDiseaseSn() {
		disease = getDiseaseService().findBySn(Integer.parseInt(sn));
		return null;
	}

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		this.sn = sn;
	}

	public Disease getDisease() {
		return disease;
	}

	public void setDisease(Disease disease) {
		this.disease = disease;
	}

	public DiseaseType getDiseaseType() {
		return diseaseType;
	}

	public void setDiseaseType(DiseaseType diseaseType) {
		this.diseaseType = diseaseType;
	}

}
